package models

import (
	"gorm.io/gorm"
	"month_zg5/client/common/global"
)

// 用户表
type User struct {
	gorm.Model
	Username string      `gorm:"type:varchar(11);not null;comment:账号"`
	Password string      `gorm:"type:varchar(100);not null;comment:密码"`
	Email    string      `gorm:"type:varchar(30);not null;comment:邮箱"`
	Phone    string      `gorm:"type:varchar(11);not null;comment:手机号码"`
	VipId    int         `gorm:"type:int(2);not null;default:0;comment:会员等级"`
	Status   int         `gorm:"type:tinyint(1);check:status IN (0,1);not null;comment:状态"`
	ReadList []*ReadList `gorm:"foreignKey:Userid" json:"ReadList"`
}

// 阅读记录表
type ReadList struct {
	gorm.Model
	Userid int
	Title  string `gorm:"type:varchar(255);not null;comment:内容"`
}

func GetReadList(id int) (*User, error) {
	user := new(User)
	return user, global.DB.Preload("ReadList").Where("user_id = ?", id).First(&user).Error

}
